package com.nameli.admin.service.impl.system;

import com.nameli.SIM.bean.entity.sys.SysUser;
import com.nameli.SIM.util.EmptyUtil;
import com.nameli.SIM.util.RedisUtil;
import com.nameli.admin.config.shiro.auth.TokenGenerator;
import com.nameli.admin.service.ShiroService;
import com.nameli.admin.service.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

/**
 * @author NAME-L
 * @Description TODO
 * @className ShiroServiceImpl
 * @date 2022-01-03 03:06:39
 */
@Component
public class ShiroServiceImpl implements ShiroService {

    @Autowired
    private RedisUtil redisUtil;

    @Autowired
    private SysUserService sysUserService;

    @Override
    public String createToken(Long userId) {
        //1.生成一个token
        String token = TokenGenerator.tokenGenerator(userId);
        //2.通过userName在redis中查找token是否存在
        SysUser sysUser = sysUserService.selectByUserId(userId);
        String hasToken = (String) redisUtil.get(sysUser.getUserName());
//        //3.如果token不存在，那么创建一个token并放进redis中
//        if (EmptyUtil.isEmpty(hasToken)) {
//            //.设置过期时间并放进redis中
//            redisUtil.set(String.valueOf(userId), token, 30);
//        }else {
//            redisUtil.set(String.valueOf(userId), token, 30);
//        }
        return token;
    }
}
